//
//  FirstCell.m
//  趣·美食
//
//  Created by dllo on 15/9/24.
//  Copyright (c) 2015年 金旭. All rights reserved.
//

#import "FirstCell.h"


@interface FirstCell ()

@property (nonatomic, strong) UIImageView *titleImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UILabel *subLabel1;
@property (nonatomic, strong) UILabel *subLabel2;


@end

@implementation FirstCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self creatImageView];
        [self creatLabel];
        
    }
    return self;
}


- (void)creatImageView {
    self.titleImage = [[UIImageView alloc] init];
    self.titleImage.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.titleImage];
  
}

- (void)creatLabel {
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
  
    
    self.countLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.countLabel];
   
    
    self.subLabel1 = [[UILabel alloc] init];
    [self.contentView addSubview:self.subLabel1];
  
    
    self.subLabel2 = [[UILabel alloc] init];
    [self.contentView addSubview:self.subLabel2];
   
}

- (void)setDeModel:(GFDetialsModel *)deModel {
    if (_deModel != deModel) {
        
        _deModel = deModel;
    }
    if (self.deModel.thumb_image_url) {
        [self.titleImage setImageWithURL:[NSURL URLWithString:self.deModel.thumb_image_url] placeholderImage:[UIImage imageNamed:@"category_1"]];
    }

    
    self.titleLabel.text = self.deModel.name;
    
    self.countLabel.text = self.deModel.calory;
    
    self.subLabel1.text = @"大卡/100克";
    self.subLabel2.text = @"(可食用部分)";
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleImage.frame = CGRectMake(ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 60, ScreenWidth / 375.0 * 60);
    
//    CGFloat width1 = [CalculateWidthOrHeigth stringWidth:self.deModel.name withHeigth:30 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
    self.titleLabel.frame = CGRectMake(ScreenWidth / 375.0 * 90, ScreenWidth / 375.0 * 20, ScreenWidth / 375.0 * 270, ScreenWidth / 375.0 * 30);
    self.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    
    CGFloat width2 = [GFCalculateWidthOrHeigth stringWidth:self.countLabel.text withHeigth:ScreenWidth / 375.0 * 20 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}];
    self.countLabel.frame = CGRectMake(ScreenWidth / 375.0 * 90, ScreenWidth / 375.0 * 60, width2, ScreenWidth / 375.0 * 20);
    self.countLabel.textColor = [UIColor redColor];
    
    CGFloat width3 = [GFCalculateWidthOrHeigth stringWidth:@"大卡/100克" withHeigth:ScreenWidth / 375.0 * 20 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    self.subLabel1.frame = CGRectMake(ScreenWidth / 375.0 * 90 + width2, ScreenWidth / 375.0 * 60, width3, ScreenWidth / 375.0 * 20);
    self.subLabel1.font = [UIFont systemFontOfSize:15];
    
    CGFloat width4 = [GFCalculateWidthOrHeigth stringWidth:@"(可食用部分)" withHeigth:ScreenWidth / 375.0 * 20 withFontDictionary:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    self.subLabel2.frame = CGRectMake(ScreenWidth / 375.0 * 90 + width2 + width3, ScreenWidth / 375.0 * 60, width4, ScreenWidth / 375.0 * 20);
    self.subLabel2.textColor = [UIColor lightGrayColor];
    self.subLabel2.font = [UIFont systemFontOfSize:15];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
